/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

 /***************************************************************************
  * Name: plugin.h
  *
  * Purpose: plugin implementation
  *
  * Developer:
  *   wen.gu , 2020-05-22
  *
  * TODO:
  *
  ***************************************************************************/

  /******************************************************************************
   **    INCLUDES
   ******************************************************************************/
#ifndef __ARA_IMPL_PLUGIN_H__
#define __ARA_IMPL_PLUGIN_H__


#include "ara/impl/types.h"
#include "ara/core/result.h"
#include "ara/core/string.h"
/******************************************************************************
**    MACROS
******************************************************************************/

/** plugin header version
 * note: plugin manager will check this version to jduagement current
 *       plugin is compatible or not?
 */
#define ARA_PLUGIN_HEADER_VER "00.01.00"

 /** the name of plugin entry, used by plugin manager */
#define ARA_PLUGIN_ENTRY_NAME "_AraPluginEntry"
#define ARA_PLUGIN_VER_FUNC_NAME "AraBaseOnPluginHeaderVersion"

/** the entry of plugin, used by plugin implementation
 ** note: this macro can't use in namespace xxx, this is c style function **
 */
#define ARA_PLUGIN_ENTRY(pluginClass, name, version, author) \
    ara::impl::Plugin* _AraPluginEntry(){ \
        panda::core::Plugin mp = new pluginClass(name, version, author); \
        return mp; \
    } \
    const char* AraBaseOnPluginHeaderVersion(){ \
        return ARA_PLUGIN_HEADER_VER; \
    }

/******************************************************************************
**    TYPE DEFINITIONS
******************************************************************************/
namespace ara
{
namespace impl
{

/******************************************************************************
**    CLASSES/FUNCTIONS DEFINITIONS
******************************************************************************/


struct ComponentCreateParam;
class Component;

class IMPL_CLASS Plugin
{
public:
    using String = ara::core::String;
public:
    Plugin(const String& name, const String& version,  const String& author)
        :mName(name),
        mVersion(version),
        mAuthor(author)
    {
        /** todo somethings */
    }

    virtual ~Plugin() { /** todo something */ }
public:
    virtual const String& name() const { return mName; }
    virtual const String& version() const { return mVersion; }
    virtual const String& author() const { return mAuthor; }

    /** create a component instance(real plugin must implement this API)
     *@parameter

     * [in] param the parameter to request the component
     *
     *@return
     *   success: Result has value(a component instance), failed: result has error code.
     */
    virtual ara::core::Result<Component*> createComponent(const ComponentCreateParam* param) = 0;
protected:
    String mName = "";
    String mVersion = "";
    String mAuthor = "";
};

} /** namespace impl */
} /** namespace ara */

/** the type of plugin entry function, used by plugin manager */
typedef ara::impl::Plugin* (*pluginEntryFunc_t)();
typedef const char* (*pluginHdrVerFunc_t)();

/** the plugin entry define */
IMPL_API_C ara::impl::Plugin* _AraPluginEntry();

/** return the version of media plugin header */
IMPL_API_C const char* AraBaseOnPluginHeaderVersion();

#endif /** !__ARA_IMPL_PLUGIN_H__ */

